package com.yanqu.road.server.cmd.activity.suoyao;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SuoYaoActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.suoyao.SuoYaoModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_SUOYAO_GET_BOOK_REWARD,desc = "锁妖塔获取爬山图鉴奖励")
public class SuoYaoGetBookRewardCmd extends AbstractCommand {

    private int bookId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        SuoYaoActivityProto.SuoYaoGetBookRewardReq req = SuoYaoActivityProto.SuoYaoGetBookRewardReq.parseFrom(packet.getBytes());
        bookId = req.getBookId();

        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(SuoYaoModule.class).getBookViewReward(bookId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret !=0){
            SuoYaoActivityProto.SuoYaoGetBookRewardResp.Builder builder = SuoYaoActivityProto.SuoYaoGetBookRewardResp.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_SUOYAO_GET_BOOK_REWARD,builder);
        }
    }
}
